<!DOCTYPE html>
<html lang="en" class="page-fill" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="utf-8">
	<title>仓库列表--快递物流系统</title>
	<link rel="stylesheet" th:href="@{/lib/layui/css/layui.css}" media="all" />
</head>
<body>
<blockquote class="layui-elem-quote quoteBox">
	<button  class="layui-btn addwarehouse_btn"  >添加</button>
</blockquote>
<table id="warehouseList" lay-filter="warehouseList"></table>

<!--操作-->
<script type="text/html" id="warehouseListBar">
	<a class="layui-btn layui-btn-xs " lay-event="edit">编辑</a>
	<button class="layui-btn layui-btn-xs layui-btn-danger delAll_btn" lay-event="del">删除</button>
</script>


<script type="text/javascript"  th:src="@{/lib/layui/layui.js}"></script>
<script type="text/javascript" th:inline="none">
	layui.use(['table','layer','jquery','form'], function(){
		table = layui.table;
		layer = parent.layer === undefined ? layui.layer : top.layer;
		$ = layui.jquery;
		form = layui.form;


		//承运商表的数据渲染
		tableIns = table.render({
			elem: '#warehouseList'
			,height: 500
			,id:  'warehouseListTable'
			,url: '/api/warehouse/list' //数据接口
			,page: true //开启分页
			,cols: [[ //表头
				{
					title: "全选",
					width: 140,
					type: "checkbox",
					fixed: 'left'}
				,{field: 'warehouseId', title: '序号', width:150, sort: true}
				,{field: 'warehouseName', title: '名称', width:200}
				,{field: 'networkName', title: '网点名称', width:200}
				,{field: 'area', title: '面积/平方米', width:150}
				,{field: 'nodeNetworkId', title: '所属网点id', width:150, sort: true}
				,{field: 'principal', title: '负责人', width:160, sort: true}
				,{field: 'contactPhone', title: '联系电话', width:150, sort: true}
				,{field: 'createTime', title: '添加时间', width:150}
				,{
					title : "操作",
					width : 240,
					align : 'center',
					toolbar : '#warehouseListBar'
				}
			]]
		});




		//添加仓库事件
		$(".addwarehouse_btn").click(function() {
			addwarehouse();
		});


		function addwarehouse(edit){
			var op = "";
			var params = "";
			var warehouseId = "";

			//通过edit是否有数据来判断请求数据的类型
			if (edit == undefined || edit == null) {
				op = "新增";
				params = "add";
			} else {
				op = "编辑";
				params = "edit";
				warehouseId = "/"+edit.warehouseId;
			}

			var index = layui.layer.open({
				title : op+"仓库",
				type : 2,
				area: ['720px','600px'],
				content : "/page/"+params+"Warehouse"+warehouseId,

			})
			//改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
			$(window).on("resize",function(){
				layui.layer.full(index);
			})
		}




		//监听行工具栏事件
		table.on('tool(warehouseList)', function(obj){
			var layEvent = obj.event;

			data = obj.data;

			if(layEvent === 'edit'){ //编辑
				addwarehouse(data);

			} else if(layEvent === 'del'){ //删除
				layer.confirm('确定删除该仓库信息？',{icon:3, title:'提示信息'},function(index){

					$.get("/api/warehouse/delete",{
						warehouseId : data.warehouseId  //将需要删除的员工编号作为参数传入
					},function(data){
						if (data.code == 200) {
							tableIns.reload(); //刷新表格数据（也即让table重新加载url）
							layer.close(index);//关闭弹出框
						} else {
							layer.close(index);//关闭弹出框
							layer.msg(data.msg,{icon:2});
						}

					})
				});
			} else if(layEvent === 'look'){ //预览
				layer.alert("此功能需要前台展示，实际开发中传入对应的必要参数进行文章内容页面访问")
			}
		});


		//批量删除
		$(".delAll_btn").click(function(){
			var checkStatus = table.checkStatus('warehouseListTable'),
					data = checkStatus.data,
					ids = [];
			if(data.length > 0) {
				for (var i in data) {
					ids.push(data[i].warehouse_id);
				}
				ids = ids.join(",");
				layer.confirm('确定删除选中的员工？', {icon: 3, title: '提示信息'}, function (index) {
					$.post("/api/warehouse/delete",{
						warehouse_id : ids  //将需要删除的newsId作为参数传入
					},function(d){
						if (d.code == 200) {
							layer.msg("删除成功", {
								"icon" : 1
							});
							tableIns.reload();
						} else {
							layer.msg(d.msg, {
								"icon" : 2
							});
						}
					})
				})
			}else{
				layer.msg("请选择需要删除的用户");
			}
		})


	});
</script>

</body>
</html>